import {Loading} from 'element-ui'

// import * as _ from 'throttle-debounce'

// loading对象
let loading

// 显示loading
function showLoading (target) {
  loading = Loading.service({
    lock: true,
    fullscreen: true,
    text: '请求中...',
    target: target || 'body'
  })
}

// 防抖：将 300ms 间隔内的关闭 loading 便合并为一次。防止连续请求时， loading闪烁的问题。
// const toHideLoading = _.debounce(() => {
//   loading.close()
//   loading = null
// }, 300)

// 隐藏loading
function hideLoading () {
  if (loading) {
    loading.close()
  }
}

export {
  showLoading,
  hideLoading
}
